﻿<%@ WebHandler Language="C#" Class="ContainerFinishCheckVue3PageHandler" %>

/* Description:新框架成品检验后端接口
 * Copyright (c) : 通力凯顿（北京）系统集成有限公司
 * Writer:zhunan 
 * create Date:2024.8.2
 */

using System;
using System.IO;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Data;
using System.Text;
using BusinessRule.DTO;
using DatabaseAccess.DBUtility;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using System.Net;
using System.Configuration;
using StackExchange.Redis;
using BusinessRule.Common;
using System.Linq;

public class ContainerFinishCheckVue3PageHandler : IHttpHandler
{
    uLMSCommonIBusiness m_Common = uMESBusinessFactory.instance.GetuLMSCommonObject();
    uLMSCheckIBusiness m_CheckObj = uMESBusinessFactory.instance.GetuLMSCheckObject();
    uLMSWorkReportIBusiness m_WorkReportObj = uMESBusinessFactory.instance.GetuLMSWorkReportObject();
    uLMSContainerIBusiness m_ContainerObj = uMESBusinessFactory.instance.GetuLMSContainerObject();
    uLMSContainercurrentinfoIBusiness m_ConCurrentinfo = uMESBusinessFactory.instance.GetuLMSContainerCurrentInfoObject();
    uLMSUserLoginIBusiness m_UserLoginObject = uMESBusinessFactory.instance.GetuLMSUserLoginObject();
    CurrentUserInfo m_UserInfo = new CurrentUserInfo();
    RedisHelper redis = new RedisHelper();

    const string redis_Lock = "MESAPP_FinishCheckPage_Lock";
    List<RedisValue> redis_reportIDs = new List<RedisValue>();
    public bool IsReusable { get { return false; } }
    public void ProcessRequest(HttpContext context)
    {
        string requestjson = "";
        using (System.IO.StreamReader reader = new StreamReader(context.Request.InputStream)) { requestjson = reader.ReadToEnd(); }
        JObject jObject = JsonConvert.DeserializeObject(requestjson) as JObject;
        if (jObject["type"] != null)
        {
            try
            {
                uMESProcessResult r = new uMESProcessResult();
                context.Response.ContentType = "text/json";
                string type = jObject["type"].ToString();
                switch (type)
                {
                    case "getFactoryCheckerList":
                        r = getFactoryCheckerList(jObject);//查询分厂检验员
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getLastFinishCheckInheritInfo":
                        r = getLastFinishCheckInheritInfo(jObject);//获取上一次成检信息（用于继承）
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "SaveFinishCheckInfo":
                        r = SaveFinishCheckInfo(jObject);//保存成品检验
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                uMESProcessResult r = new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "500", Message = e.Message };
                context.Response.ContentType = "text/json";
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }
    }

    //查询分厂下的检验员
    uMESProcessResult getFactoryCheckerList(JObject obj)
    {
        DataTable dtResult = m_Common.GetEmplyeeListByRole("检验员", obj["factoryid"].ToString());
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //获取相同件号相同工序成检的继承信息
    uMESProcessResult getLastFinishCheckInheritInfo(JObject obj)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("ProductName", obj["productname"].ToString());
        para.Add("WorkflowStepName", obj["workflowstepname"].ToString());
        DataTable dtInherit = m_CheckObj.GetLastFinishCheckInheritInfo(para);
        if (dtInherit.Rows.Count > 0)
        {
            DataRow row = dtInherit.Rows[0];
            DataTable dtDetail = m_CheckObj.GetFinishCheckInfoDetail(string.Format("C.CONTAINERFINISHEDCHECKINFOID='{0}'", row["CONTAINERFINISHEDCHECKINFOID"].ToString()));
            dtDetail.Columns.Add("techniquecondition");//技术条件
            dtDetail.Columns.Add("checknote");//附注信息
            foreach (DataRow dr in dtDetail.Rows)
            {
                dr["techniquecondition"] = row["TECHNIQUECONDITION"].ToString();
                dr["checknote"] = row["CHECKNOTE"].ToString();
            }
            foreach (DataColumn col in dtDetail.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }
            return new uMESProcessResult() { ReturnData = dtDetail, RowCount = dtDetail.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
        }
        return new uMESProcessResult() { ReturnData = new DataTable(), RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //校验成品检验数据
    bool ValidateFinishCheckData(JObject obj, ref List<ContainerFinishedCheckInfoDTO> checkInfoDTO, DataTable Lossdt, DataTable wgContainerInfo, ref string strInfo)
    {
        string strType = wgContainerInfo.Rows[0]["containertype"].ToString();//批次类型
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");

        foreach (DataRow uldr in wgContainerInfo.Rows)
        {
            ContainerFinishedCheckInfoDTO newdto = new ContainerFinishedCheckInfoDTO();
            if (Convert.ToInt64(uldr["CheckQty"]) < Convert.ToInt64(uldr["WipQty"]))
            {
                strInfo = "待检数必须大于或者等于在制数";
                return false;
            }
            newdto.FactoryID = m_UserInfo.FactoryID;
            newdto.CheckerID = m_UserInfo.EmployeeID;
            if (strType != "7")
            {
                newdto.AcceptanceQty = Convert.ToInt32(obj["acceptanceQty"].ToString());//【检验总数】文本框
                newdto.CheckQty = Convert.ToInt32(obj["submitQty"].ToString());//【提交数】文本框
                newdto.LossQty = Convert.ToInt32(obj["sumLossQty"].ToString());//【报废数】文本框
                newdto.DefectQty = Convert.ToInt32(obj["sumDefeatQty"].ToString());//【超差数】文本框
                newdto.ReworkQty = Convert.ToInt32(obj["sumReworkQty"].ToString());//【返修数文本框】
            }
            else
            {
                // 单价单卡情况判断
                foreach (DataRow dr in Lossdt.Rows)
                {
                    if (dr["ContainerID"].ToString() == uldr["ContainerID"].ToString())
                    {
                        newdto.LossQty = Convert.ToInt32(dr["LossQty"].ToString());//报废数
                        newdto.AcceptanceQty = 1 - newdto.LossQty; // 合格数为 1 - 报废数
                        newdto.CheckQty = 1; // 单件单卡的检验数量都为 1
                        newdto.DefectQty = Convert.ToInt32(dr["DefectQty"].ToString());
                        newdto.ReworkQty = Convert.ToInt32(dr["ReworkQty"].ToString());

                        if (m_CheckObj.ContainerCheckValidate(dr["ContainerStepWorkReportID"].ToString(), 1) == false) // 已有记录
                        {
                            strInfo = "批次【" + dr["ChildContainer"].ToString() + "】此序对应的报工记录已存在检验记录";
                            return false;
                        }
                        if (!m_CheckObj.IsVaildWorkReportForCheck(dr["ContainerStepWorkReportID"].ToString(), 1))
                        {
                            strInfo = "批次工序的报工记录已经撤销，请刷新页面";
                            return false;
                        }
                    }
                }
            }
            newdto.ContainerID = uldr["ContainerID"].ToString();
            newdto.WorkflowstepID = uldr["WorkflowstepID"].ToString();
            newdto.CheckNote = obj["checkNote"].ToString();//附注
            newdto.BatchNO = obj["batchNO"].ToString();//炉批次号
            newdto.CheckResult = obj["checkResult"].ToString();//送检结论
            newdto.DefectBillNO = obj["defectBillNo"].ToString();//超差审理单
            newdto.OtherQualityResult = obj["otherQualityResult"].ToString();//其他质量文件
            newdto.TechniqueCondition = obj["techniqueCondition"].ToString();//技术条件
            newdto.ContainerFinishedCheckInfoID = Guid.NewGuid().ToString();
            newdto.AcceptanceQty2 = newdto.AcceptanceQty - newdto.DefectQty - newdto.ReworkQty; //合格数2
            checkInfoDTO.Add(newdto);
        }

        return true;
    }

    //保存成品检验
    uMESProcessResult SaveFinishCheckInfo(JObject obj)
    {
        CurrentUserInfo m_UserInfo = m_Common.GetUserInfo(obj["employeename"].ToString(), "");
        DataTable wgContainerInfo = JsonConvert.DeserializeObject<DataTable>(obj["containerList"].ToString());//流水卡信息表格原始数据
        DataTable dtChildList = JsonConvert.DeserializeObject<DataTable>(obj["lossInfoList"].ToString());//报废表格数据
        DataTable CheckerData = JsonConvert.DeserializeObject<DataTable>(obj["CheckerData"].ToString());//检测内容表格
        DataRow cudr = wgContainerInfo.Rows[0];//批次检验记录第一行数据
        string strMessage = "";
        string strType = cudr["containertype"].ToString();

        List<ContainerFinishedCheckInfoDTO> checkInfoDTO = new List<ContainerFinishedCheckInfoDTO>();
        if (ValidateFinishCheckData(obj, ref checkInfoDTO, dtChildList, wgContainerInfo, ref strMessage) == false)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = strMessage };
        };

        ServerHostInfo host = new ServerHostInfo();
        string APIUserName = "", APIPassword = "";
        // 根据分厂获取域用户信息
        m_UserLoginObject.GetDomainUser(m_UserInfo.Factory, ref APIUserName, ref APIPassword);
        host.UserName = APIUserName;
        host.Password = APIPassword;

        DataTable levelAttributes = m_Common.GetFatoryAttributes(m_UserInfo.FactoryID);//获取分厂配置项
        DataRow[] datarows = levelAttributes.Select("USERATTRIBUTENAME='入库流程'");
        string strWF = "", strWFRev = "";
        if (datarows.Length > 0)
        {
            string[] strWorkflows = datarows[0]["ATTRIBUTEVALUE"].ToString().Split('：');
            strWF = strWorkflows[0];
            strWFRev = strWorkflows[1];
        }
        datarows = levelAttributes.Select("USERATTRIBUTENAME='入库工序'");
        string strStep = "";
        if (datarows.Length > 0)
        {
            strStep = datarows[0]["ATTRIBUTEVALUE"].ToString();
        }

        // 如果超报存在，则获取当前检验报工记录报工时间最大的报工记录 ID，超报只会在此条记录产生
        int changevalueqty = 0;
        string Max_date_workReportID = "";
        DataTable workreport_dt = dtChildList.DefaultView.ToTable(true, new string[] { "ContainerID", "ContainerStepWorkReportID" });
        DataRow[] workreport_dr;
        // 增加 Redis 锁
        foreach (DataRow report in workreport_dt.Rows)
        {
            if (redis.ExistsSet(redis_Lock, report["ContainerStepWorkReportID"].ToString())) // 缓存存在
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "有报工记录正被检验中,请稍后再试" };
            }
            else
            {
                redis_reportIDs.Add(report["ContainerStepWorkReportID"].ToString());
                redis.AddSet(redis_Lock, report["ContainerStepWorkReportID"].ToString());
                redis.SetKeyExpiry(redis_Lock, TimeSpan.FromMinutes(20)); // 设定超期时间 20 分钟
            }
        }

        // 处理逻辑顺序：先存数量调整记录，再存检验记录，最后调整在制数 
        foreach (ContainerFinishedCheckInfoDTO checkdto in checkInfoDTO)
        {
            // 数量批成检只会有一条成检记录，查看是否有超报,并获取最大报工时间的报工记录 ID
            if (strType == "2")
            {
                if (checkdto.CheckQty > Convert.ToInt32(cudr["WipQty"]))
                {
                    changevalueqty = checkdto.CheckQty - Convert.ToInt32(cudr["WipQty"]);
                    double max_data = -1;
                    foreach (DataRow vdr in dtChildList.Rows)
                    {
                        if (Convert.ToDouble(DateTime.Parse(vdr["CreateDate"].ToString()).ToOADate()) > max_data)
                        {
                            max_data = Convert.ToDouble(DateTime.Parse(vdr["CreateDate"].ToString()).ToOADate());
                            Max_date_workReportID = vdr["ContainerStepWorkReportID"].ToString();
                        }
                    }
                }
            }
            else
            {
                changevalueqty = 0;
            }

            // 存数量调整记录
            if (!(checkdto.LossQty == 0 && changevalueqty == 0))
            {
                if (checkdto.LossQty != 0 && changevalueqty == 0) // 有报废，无超报
                {
                    CheckQtyChangeLoss(dtChildList, checkdto, strType, m_UserInfo);
                }
                else if (checkdto.LossQty != 0 && changevalueqty != 0) // 有报废，有超报（存在超报的都是数量批）
                {
                    // 添加批次数量改变记录--超报记录
                    CheckQtyChangeAdd(dtChildList, Max_date_workReportID, checkdto, changevalueqty, m_UserInfo);
                    // 添加批次数量改变记录--报废记录
                    CheckQtyChangeLoss(dtChildList, checkdto, strType, m_UserInfo);
                }
                else if (checkdto.LossQty == 0 && changevalueqty != 0) // 无报废，有超报（存在超报的都是数量批）
                {
                    CheckQtyChangeAdd(dtChildList, Max_date_workReportID, checkdto, changevalueqty, m_UserInfo);
                }
            }

            // 进行数量调整
            if (changevalueqty - checkdto.LossQty != 0)
            {
                if (strType == "3")
                {
                    if (!m_ContainerObj.ChangeContainerQty(checkdto.ContainerID, changevalueqty - checkdto.LossQty))
                    {
                        return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "数量更新失败" };
                    }
                    DataView dv = dtChildList.DefaultView;
                    dv.RowFilter = "lossQty <> 0";
                    DataTable childdt = dv.ToTable();
                    foreach (DataRow rr in childdt.Rows)
                    {
                        // 子序号批次置为关闭
                        ExcuteEntity exuteEntity = new ExcuteEntity("container", ExcuteEntity.ExcuteTypeEnum.update);
                        exuteEntity.ExcuteFileds = new List<FieldEntity> { 
                            new FieldEntity("status", 2, FieldEntity.FieldTypeEnum.Numer), 
                            new FieldEntity("qty", 0, FieldEntity.FieldTypeEnum.Numer) 
                        };
                        exuteEntity.WhereFileds = new List<FieldEntity> { new FieldEntity("Containerid", rr["ChildContainerID"].ToString(), FieldEntity.FieldTypeEnum.Str) };
                        DatabaseHelper.ExecuteDataByEntity(exuteEntity);
                    }
                    LogHelp.WriteOrcale("检验日志记录-成检" + "@^" + "批次：" + checkdto.ContainerID + "@^" + "工序：" + checkdto.WorkflowstepID + " 数量调整成功" + "@^" + Guid.NewGuid().ToString() + "@^" + m_UserInfo.FullName);
                }
                else
                {
                    if (!m_ContainerObj.ChangeContainerQty(checkdto.ContainerID, changevalueqty - checkdto.LossQty))
                    {
                        return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "更新批次数量失败" };
                    }
                    LogHelp.WriteOrcale("检验日志记录-成检" + "@^" + "批次：" + checkdto.ContainerID + "@^" + "工序：" + checkdto.WorkflowstepID + " 数量调整成功" + "@^" + Guid.NewGuid().ToString() + "@^" + m_UserInfo.FullName);
                }
            }

            // 存成检记录
            if (m_CheckObj.AddContainerFinishedCheckInfo(checkdto))
            {
                // 更新检验序的分厂和报工人 add:Wangjh 20171218
                UpdateReportFactoryAndWorker(dtChildList, m_UserInfo);
                ContainerFinishedCheckDetailDTO checkdetailinfo;
                // 添加成品检验明细（量具检验+外观检查+尺寸检查等信息）
                foreach (DataRow row in CheckerData.Rows)
                {
                    checkdetailinfo = new ContainerFinishedCheckDetailDTO();
                    checkdetailinfo.CheckDetailName = row["CheckName"].ToString();
                    checkdetailinfo.CheckDetailValue = row["CheckValue"].ToString();
                    checkdetailinfo.EmployeeID = row["CheckEmployeeID"].ToString();
                    checkdetailinfo.ChildContainerID = string.Empty;
                    checkdetailinfo.ContainerFinishedCheckInfoID = checkdto.ContainerFinishedCheckInfoID;
                    m_CheckObj.AddContainerFinishedCheckDetailInfo(checkdetailinfo);
                }
                // 若有待处理记录，标记为无效
                m_CheckObj.UpdateContainerCheckSuspending(checkdto.ContainerID, checkdto.WorkflowstepID);
            }

            // 更新 ID 和报废数数据到报工表
            workreport_dr = workreport_dt.Select(String.Format("ContainerID='{0}'", checkdto.ContainerID));
            // 更新报工表报废数
            if (!UpdateContainerStepWorkReport(checkdto, dtChildList, workreport_dr, ref strMessage))
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = strMessage };
            }

            if (checkdto.AcceptanceQty == 0)
            {
                continue;
            }
            else
            {
                //listContaienrIDs.Add(checkdto.ContainerID);
            }
            // 检查总表 stepcheckNum,firstCheckNum
            string strUpdateinfo = "";
            strUpdateinfo = m_ConCurrentinfo.UpdateContainerCurrentinfoCheckInfo(checkdto.ContainerID, checkdto.WorkflowstepID);

            if (strType == "7")
            {
                foreach (DataRow uldr in wgContainerInfo.Rows)
                {
                    if (checkdto.ContainerID == uldr["ContainerID"].ToString())
                    {
                        m_CheckObj.MoveNextStep(new Dictionary<string, string>{
                            {"ContainerID", uldr["ContainerID"].ToString()},
                            {"WorkflowStepID", uldr["WorkFlowStepID"].ToString()},
                            {"WorkflowID", uldr["WorkflowID"].ToString()},
                            {"Sequence", uldr["Sequence"].ToString()},
                            {"ContainerName", uldr["ContainerName"].ToString()}
                        },
                        host,
                        1,
                        levelAttributes,
                        m_UserInfo,
                        ref strMessage);

                        break;
                    }
                }
            }
            else
            {
                string strMoveNextStep = "";
                m_CheckObj.MoveNextStep(new Dictionary<string, string> {
                        {"ContainerID", cudr["ContainerID"].ToString()},
                        {"WorkflowStepID", cudr["WorkFlowStepID"].ToString()},
                        {"WorkflowID", cudr["WorkflowID"].ToString()},
                        {"Sequence", cudr["Sequence"].ToString()},
                        {"ContainerName", cudr["ContainerName"].ToString()}
                    },
                    host,
                    Convert.ToInt32(obj["acceptanceQty"].ToString()),
                    levelAttributes,
                    m_UserInfo,
                    ref strMoveNextStep);
            }
        }

        //成检成功移除redis MESAPP_FinishCheckPage_Lock锁
        redis.RemoveSet(redis_Lock, redis_reportIDs.ToArray());
        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = "检验成功" };
    }

    /// <summary>
    /// 增加成品检验记录 --报废 add by tianFW 2018年11月6日
    /// </summary>
    /// <param name="dtChildList">明细表</param>
    /// <param name="stepCheck">检验记录</param>
    /// <param name="strtype">批次类型</param>
    /// <param name="strtype">用户信息</param>
    void CheckQtyChangeLoss(DataTable dtChildList, ContainerFinishedCheckInfoDTO stepCheck, string strtype, CurrentUserInfo m_UserInfo)
    {
        string containerID = "";
        foreach (DataRow dr in dtChildList.Rows)
        {
            if (dr["LossQty"].ToString() != "0" && dr["containerID"].ToString() == stepCheck.ContainerID)
            {
                containerID = dr["containerID"].ToString();
                if (strtype == "3") // 批量带子序号
                {
                    containerID = dr["ChildContainerID"].ToString();
                }
                AddQtyChangRecord(
                    stepCheck.ContainerFinishedCheckInfoID,
                    containerID,
                    2,
                    -(Convert.ToInt32(dr["LossQty"])),
                    dr["ReasonID"].ToString(),
                    dr["ContainerStepWorkReportID"].ToString(),
                    stepCheck.WorkflowstepID,
                    m_UserInfo);
            }
        }
    }

    /// <summary>
    /// 添加批次数量改变记录 create by tianFW  2018年8月30日
    /// </summary>
    /// <param name="checkInfoID">检验记录ID</param>
    /// <param name="containerID">批次ID</param>
    /// <param name="type">添加记录类型 1 添加 2 报废</param>
    /// <param name="qty">改变数量</param>
    /// <param name="ReasonID">改变原因ID</param>
    /// <param name="ContainerStepWorkReportID">报工id</param>
    /// <param name="workflowStepID">工序ID</param>
    /// <param name="m_UserInfo">用户信息</param>
    private void AddQtyChangRecord(string checkInfoID, string containerID, int type, int qty, string ReasonID, string ContainerStepWorkReportID, string workflowStepID, CurrentUserInfo m_UserInfo)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para["containerCheckInfoID"] = checkInfoID;
        para["containerID"] = containerID;
        para["changeQtyType"] = type.ToString();
        para["qty"] = qty.ToString();
        para["reasonID"] = ReasonID;
        para["containerStepWorkReportID"] = ContainerStepWorkReportID;
        para["scrapSourceType"] = "2"; // 成品检验类型
        para["EmployeeID"] = m_UserInfo.EmployeeID;
        para["WorkflowstepID"] = workflowStepID;
        m_ContainerObj.AddCheckQtyChangeRecord(para);
    }

    /// <summary>
    /// 增加成品检验记录 --超报 add by tianFW 2018 年 11 月 6 日
    /// </summary>
    /// <param name="dtChildList">明细表</param>
    /// <param name="Max_date_workReportID"最大报工时间报工ID></param>
    /// <param name="stepCheck">检验记录</param>
    /// <param name="changevalueqty">超报数量</param>
    /// <param name="m_UserInfo">用户信息</param>
    void CheckQtyChangeAdd(DataTable dtChildList, string Max_date_workReportID, ContainerFinishedCheckInfoDTO stepCheck, int changevalueqty, CurrentUserInfo m_UserInfo)
    {
        foreach (DataRow dr in dtChildList.Rows)
        {
            if (dr["ContainerStepWorkReportID"] == Max_date_workReportID)
            {
                // 获取批次数量变更原因代码 ID
                string reasonID = "";
                DataTable qtyadjustrea_dt = m_Common.GetQtyAdjustReason();
                foreach (DataRow dr_ in qtyadjustrea_dt.Rows)
                {
                    if (dr_["qtyadjustreasonname"] == "报工数量变更")
                    {
                        reasonID = dr_["qtyadjustreasonid"].ToString();
                        break;
                    }
                }
                AddQtyChangRecord(
                    stepCheck.ContainerFinishedCheckInfoID,
                    dr["containerID"].ToString(),
                    1,
                    changevalueqty,
                    reasonID,
                    Max_date_workReportID,
                    stepCheck.WorkflowstepID,
                    m_UserInfo);
                break;
            }
        }
    }

    /// <summary>
    /// 更新自动报工的分厂和报工人
    /// add:Wangjh 20171215 
    /// </summary>
    void UpdateReportFactoryAndWorker(DataTable dtChildList, CurrentUserInfo m_UserInfo)
    {
        // add:Wangjh 20171215 此处增加更新自动的报工记录
        Dictionary<string, object> updatePara = new Dictionary<string, object>();
        string containerStepWorkReportID = "";
        for (int i = 0; i < dtChildList.Rows.Count; i++)
        {
            if (!string.IsNullOrWhiteSpace(dtChildList.Rows[i]["fullname"].ToString()))
            {
                continue;
            }
            if (containerStepWorkReportID == dtChildList.Rows[i]["ContainerStepWorkReportID"].ToString())
            {
                continue;
            }
            updatePara["FactoryID"] = m_UserInfo.FactoryID;
            updatePara["WorkerID"] = m_UserInfo.EmployeeID;
            containerStepWorkReportID = dtChildList.Rows[i]["ContainerStepWorkReportID"].ToString();
            updatePara["ContainerStepWorkReportID"] = containerStepWorkReportID;
            // 更新报表表报废数
            m_CheckObj.UpdateContainerStepWorkReport(updatePara);
        }
    }

    /// <summary>
    /// 更新报工表报废数 modify by tianFW 2018 年 11 月 6 日
    /// </summary>
    /// <param name="stepcheckdto">成检记录实体对象</param>
    /// <param name="dtChildList">报废明细信息表</param>
    /// <returns></returns>
    bool UpdateContainerStepWorkReport(ContainerFinishedCheckInfoDTO stepcheckdto, DataTable dtChildList, DataRow[] workreport_dr, ref string strMsg)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        int lossQty = 0;
        foreach (DataRow r in workreport_dr)
        {
            lossQty = 0;
            foreach (DataRow dr in dtChildList.Rows)
            {
                if (dr["ContainerStepWorkReportID"].ToString() == r["ContainerStepWorkReportID"].ToString() && dr["LossQty"].ToString() != "0")
                {
                    lossQty += Convert.ToInt32(dr["LossQty"]);
                }
            }
            para.Clear();
            para["LossQty"] = lossQty.ToString();
            para["ContainerStepWorkReportID"] = r["ContainerStepWorkReportID"].ToString();
            para["ContainerFinishedCheckInfoID"] = stepcheckdto.ContainerFinishedCheckInfoID;
            if (!m_WorkReportObj.UpDateLossQtyInfo(para))
            {
                strMsg = "反写报工报废和成检记录 ID 失败";
                return false;
            }
        }
        return true;
    }
}